<template>
    <div>
        <!-- 面包屑区域 -->
        <BreadView>
            <BreadItem>首页</BreadItem>
            <BreadItem>购物车</BreadItem>
        </BreadView>
        <div class="cart">
            <table>
                <thead>
                    <tr>
                        <th width="120"><input type="checkbox" name="" id="" />全选</th>
                        <th width="400">商品信息</th>
                        <th width="220">单价</th>
                        <th width="180">数量</th>
                        <th width="180">小计</th>
                        <th width="140">操作</th>
                    </tr>
                </thead>
                <!-- 有效商品 -->
                <tbody >
                    <tr v-for="(item, key) in list" :key="item.skuid" >
                        <td>
                            <input type="checkbox" name="" id="" v-model="item.selected"/>
                        </td>
                        <td >
                            <div class="goods">
                                <RouterLink to="/">
                                    <img :src="item.img" alt="" />
                                </RouterLink>
                                <div>
                                    <p class="name ellipsis">
                                        {{ item.goodsname }}
                                    </p>
                                    <!-- 选择规格组件 -->
                                </div>
                            </div>
                        </td>
                        <td class="tc">
                            <p>
                                &yen;
                                {{ item.price }}
                            </p>
                            <p>
                                比加入时降价
                                <span class="red">&yen;
                                    {{ item.oldPrice - item.price }}
                                </span>
                            </p>
                        </td>
                        <td class="tc">
                            {{ item.count }}
                            <xtx-numbox :cont="item.count"></xtx-numbox>
                        </td>
                        <td class="tc">
                            <p class="f16 red">&yen;200.00</p>
                        </td>
                        <td class="tc">
                            <p><a href="javascript:;">移入收藏夹</a></p>
                            <p>
                                <a class="green" href="javascript:;" @click="dellist(key)">删除</a>
                            </p>
                            <p><a href="javascript:;">找相似</a></p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- 操作栏 -->
        <div class="action">
            <div class="batch">
                <input type="checkbox" name="" id="" />全选
                <a href="javascript:;">删除商品</a>
                <a href="javascript:;">移入收藏夹</a>
                <a href="javascript:;">清空失效商品</a>
            </div>
            <div class="total">
                共 7 件商品，已选择 2 件，商品合计：
                <span class="red">¥400</span>
                <button type="primary" @click="order">下单结算</button>
            </div>
        </div>
        <!-- 同类商品推荐区域 -->
        <!-- <goods-relevant :relevantlist="relevantlist" :relevant="relevant"></goods-relevant> -->

    </div>
</template>
  
<script>
import BreadItem from '@/components/bread/BreadItem.vue'
import BreadView from '@/components/bread/BreadView.vue'
import { getSame } from "@/utils/api/detailapi";
// import GoodsRelevant from "@/components/goodsdetail/GoodsRelevant.vue";
import XtxNumbox from "../utils/XtxNumbox.vue";
export default {
    components: {
        BreadItem,
        BreadView,
        // GoodsRelevant,
        XtxNumbox,
    },
    data() {
        return {
            relevantlist: [],
            relevant: "猜你喜欢",
        };
    },

    mounted() {
        this.xuan1(this.$route.query.id);
        console.log(this.list)
    },
    computed: {
        list() {
            return this.$store.state.cart.list;
        },
    },

    methods: {
        //同类商品
        async xuan1(id) {
            var arr = {
                id: id,
                limit: 16,
            };
            let resa = await getSame(arr);
            // console.log(resa);
            this.relevantlist = resa.result;
        },
        dellist(key) {
            // alert(123)
            this.$confirm({ text: "提示语", title: "您确认从购物车删除该商品吗" })
                .then(() => {
                    this.$store.commit('cart/delCart', key)
                })
                .catch(() => { });
        },
        /* 下单按钮跳转页面 */
        order() {
            this.$router.push('/member/order');
        }
    },
};
</script>
  
<style lang="scss" scoped>
@import "@/assets/css/color.scss";
.cart {
    background-color: white;
}
.tc {
    text-align: center;

    .xtx-numbox {
        margin: 0 auto;
        width: 120px;
    }
}
td {
    border-bottom: 1px solid #ccc ;
}
.red {
    color: $priceColor;
}

.green {
    color: $xtxColor;
}

.f16 {
    font-size: 16px;
}

.goods {
    display: flex;
    align-items: center;

    img {
        width: 100px;
        height: 100px;
    }

    >div {
        width: 280px;
        font-size: 16px;
        padding-left: 10px;

        .attr {
            font-size: 14px;
            color: #999;
        }
    }
}

.action {
    display: flex;
    background: #fff;
    margin-top: 20px;
    height: 80px;
    align-items: center;
    font-size: 16px;
    justify-content: space-between;
    padding: 0 30px;

    .xtx-checkbox {
        color: #999;
    }

    .batch {
        a {
            margin-left: 20px;
        }
    }

    .red {
        font-size: 18px;
        margin-right: 20px;
        font-weight: bold;
    }
    button {
        width: 200px;
        line-height: 50px;
        background-color: #27ba9b;
        border: none;
        border-radius: 8px;
        color: white;
    }
}

.tit {
    color: #666;
    font-size: 16px;
    font-weight: normal;
    line-height: 50px;
}

.xtx-cart-page {
    .cart {
        background: #fff;
        color: #666;

        table {
            border-spacing: 0;
            border-collapse: collapse;
            line-height: 24px;

            th,
            td {
                padding: 10px;
                border-bottom: 1px solid #f5f5f5;

                &:first-child {
                    text-align: left;
                    padding-left: 30px;
                    color: #999;
                }
            }

            th {
                font-size: 16px;
                font-weight: normal;
                line-height: 50px;
            }
        }
    }
}
</style>